
// <copyright file="AbstractPingResultProcessor.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The abstract ping result processor.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Net
{
    using System;

    /// <summary>
    /// The abstract ping result processor.
    /// </summary>
    public abstract class AbstractPingResultProcessor : IPingResultProcessor
    {
        #region Public Methods and Operators

        /// <summary>
        /// The process ping result.
        /// </summary>
        /// <param name="pingResult">
        /// The ping result.
        /// </param>
        /// <param name="commandPrompt">
        /// The command prompt.
        /// </param>
        /// <returns>
        /// The <see cref="decimal"/>.
        /// </returns>
        public abstract decimal ProcessPingResult(string pingResult, string commandPrompt);

        /// <summary>
        /// The remove padding.
        /// </summary>
        /// <param name="output">
        /// The output.
        /// </param>
        /// <param name="commandPrompt">
        /// The command prompt.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public virtual string RemovePadding(string output, string commandPrompt)
        {
            string result = output;
            if (!string.IsNullOrEmpty(output))
            {
                int ind = output.LastIndexOf(Environment.NewLine, StringComparison.Ordinal);
                if (ind > -1)
                {
                    result = output.Substring(0, ind);
                }
            }

            return string.IsNullOrEmpty(result) ? " " : result;
        }

        #endregion Public Methods and Operators
    }
}
